package Algorithm.LinkedListProblem;

/**
 * @Author cj
 * @Date 2022/1/6 20:21
 */
public class removeValue {

    static class Node {
        public int value;
        public Node next;

        public Node(int val) {
            this.value = val;
        }
    }

    public static Node removeValue1(Node head, int num) {
        // 找到第一个值不为num的节点
        while (head != null) {
            if (head.value != num) {
                break;
            }
            head = head.next;
        }
        Node pre = head, cur = head;
        while (cur != null) {
            if (cur.value == num) {
                pre.next = cur.next;
            } else {
                pre = cur;
            }
            cur = cur.next;
        }
        return head;
    }

}
